home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / djgpp / contrib / dvx / demos / xeyes / transfor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-15  |  2.5 KB  |  125 lines

  1. /*
  2.  * transformed coordinate system objects for X
  3.  */
  4. #if defined(PROTO) || defined(PROTO1)
  5. #define NeedFunctionPrototypes    0
  6. #define NeedFunctionPtrPrototypes    1
  7. #include "transform.fd1"
  8. #endif
  9.  
  10. #ifdef PROTO
  11. #include "transform.fd2"
  12. #endif
  13.  
  14. #include    <stdlib.h> /* POHC 91/01/23 */
  15.  
  16. # include    <X11/Xlib.h>
  17. # include    "transform.h"
  18.  
  19.  
  20. static XPoint *
  21. TranslatePoints (points, n_points, t, mode)
  22. TPoint    *points;
  23. int    n_points;
  24. Transform    *t;
  25. int    mode;
  26. {
  27.     XPoint    *xpoints;
  28.     int    i;
  29.     double    xoff = 0.0, yoff = 0.0;
  30.  
  31.     xpoints = (XPoint *) malloc (n_points * sizeof (*xpoints));
  32.     if (!xpoints)
  33.         return 0;
  34.     for (i = 0; i < n_points; i++) {
  35.         xpoints[i].x = Xx(points[i].x + xoff, points[i].y + yoff, t);
  36.         xpoints[i].y = Xy(points[i].x + xoff, points[i].y + yoff, t);
  37.         if (mode == CoordModePrevious) {
  38.             xoff += points[i].x;
  39.             yoff += points[i].y;
  40.         }
  41.     }
  42.     return xpoints;
  43. }
  44.  
  45. TFillPolygon (dpy, d, gc, t, points, n_points, shape, mode)
  46. register Display    *dpy;
  47. Drawable        d;
  48. GC            gc;
  49. Transform        *t;
  50. TPoint            *points;
  51. int            n_points;
  52. int            shape;
  53. int            mode;
  54. {
  55.     XPoint    *xpoints;
  56.  
  57.     xpoints = TranslatePoints (points, n_points, t, mode);
  58.     if (xpoints) {
  59.         XFillPolygon (dpy, d, gc, xpoints, n_points, shape,
  60.                 CoordModeOrigin);
  61.         free (xpoints);
  62.     }
  63. }
  64.  
  65. TDrawArc (dpy, d, gc, t, x, y, width, height, angle1, angle2)
  66.     register Display    *dpy;
  67.     Drawable        d;
  68.     GC            gc;
  69.     Transform        *t;
  70.     double            x, y, width, height;
  71.     int            angle1, angle2;
  72. {
  73.     int    xx, xy, xw, xh;
  74.  
  75.     xx = Xx(x,y,t);
  76.     xy = Xy(x,y,t);
  77.     xw = Xwidth (width, height, t);
  78.     xh = Xheight (width, height, t);
  79.     if (xw < 0) {
  80.         xx += xw;
  81.         xw = -xw;
  82.     }
  83.     if (xh < 0) {
  84.         xy += xh;
  85.         xh = -xh;
  86.     }
  87.     XDrawArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2);
  88. }
  89.  
  90. TFillArc (dpy, d, gc, t, x, y, width, height, angle1, angle2)
  91.     register Display    *dpy;
  92.     Drawable        d;
  93.     GC            gc;
  94.     Transform        *t;
  95.     double            x, y, width, height;
  96.     int            angle1, angle2;
  97. {
  98.     int    xx, xy, xw, xh;
  99.  
  100.     xx = Xx(x,y,t);
  101.     xy = Xy(x,y,t);
  102.     xw = Xwidth (width, height, t);
  103.     xh = Xheight (width, height, t);
  104.     if (xw < 0) {
  105.         xx += xw;
  106.         xw = -xw;
  107.     }
  108.     if (xh < 0) {
  109.         xy += xh;
  110.         xh = -xh;
  111.     }
  112.     XFillArc (dpy, d, gc, xx, xy, xw, xh, angle1, angle2);
  113. }
  114.  
  115. SetTransform (t, xx1, xx2, xy1, xy2, tx1, tx2, ty1, ty2)
  116. Transform    *t;
  117. int        xx1, xx2, xy1, xy2;
  118. double        tx1, tx2, ty1, ty2;
  119. {
  120.     t->mx = ((double) xx2 - xx1) / (tx2 - tx1);
  121.     t->bx = ((double) xx1) - t->mx * tx1;
  122.     t->my = ((double) xy2 - xy1) / (ty2 - ty1);
  123.     t->by = ((double) xy1) - t->my * ty1;
  124. }
  125.